package com.zl.tesseract.scanner.greendao.services;

import com.zl.tesseract.scanner.beans.OutBean;
import com.zl.tesseract.scanner.greendao.GreenDaoHelper;
import com.zl.tesseract.scanner.greendao.db.OutBeanDao;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

public class OutBeanService {

    private static OutBeanDao outBeanDao;


    public static void saveOne(OutBean outBean) {
        if(outBeanDao == null){
            outBeanDao = GreenDaoHelper.getDaoSession().getOutBeanDao();
        }
        outBeanDao.save(outBean);
    }

    public static void saveList(List<OutBean> list) {
        for (OutBean blastDicBean : list) {
            saveOne(blastDicBean);
        }
    }

    public static List<OutBean> findAll() {
        if(outBeanDao == null){
            outBeanDao = GreenDaoHelper.getDaoSession().getOutBeanDao();
        }
        return outBeanDao.loadAll();
    }

    public static OutBean findOneByOrderId(String order_id) {
        if(outBeanDao == null){
            outBeanDao = GreenDaoHelper.getDaoSession().getOutBeanDao();
        }
        QueryBuilder<OutBean> queryBuilder = outBeanDao.queryBuilder();
        return queryBuilder.where(OutBeanDao.Properties.Order_id.eq(order_id)).unique();
    }

    public static void deleteAll() {
        if(outBeanDao == null){
            outBeanDao = GreenDaoHelper.getDaoSession().getOutBeanDao();
        }
        outBeanDao.deleteAll();
    }

    public static void deleteOne(OutBean blastDicBean) {
        if(outBeanDao == null){
            outBeanDao = GreenDaoHelper.getDaoSession().getOutBeanDao();
        }
        outBeanDao.delete(blastDicBean);
    }

}